package com.example.leetcode.stack_code;

import java.util.HashMap;
import java.util.Stack;

public class Test1 {

    public static void main(String[] args) {
        boolean have=testString("(*)");
        System.out.println(have);
    }

    private static boolean testString(String s) {
        Stack<String> stack=new Stack<>();
        HashMap<String,String> map=new HashMap<>();
        map.put(")","(");
        map.put("]","[");
        map.put("}","{");
        for (char c : s.toCharArray()) {
            String s1 = String.valueOf(c);
            if(!map.containsKey(s1)){
                stack.push(s1);
            }else if(stack.isEmpty() || !stack.pop().equals( map.get(s1))) {
                return false;
            }
        }
        return  stack.isEmpty();
    }

}
